#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;
const int maxn=100000, maxq=100000;

class Pit {
    public:
        int time, id, from;

        static bool cmp(Pit &a, Pit &b) {return a.time<b.time;}
};

class Ques {
    public:
        ll x;
        int id;

        static bool cmp(Ques &a, Ques &b) {return a.x<b.x;}
};

void initPit(int n, int a[], Pit pit[]) {
    static int pos[2*maxn+2], b[maxn+1];
    memcpy(b, a, sizeof b);
    pos[0] = 0;
    pit[0].time = 0;
    for (int i=0; i<=2*n+1; i++) {
        if (b[i%(n+1)]>1) {
            pos[++pos[0]] = i;
        } else if (b[i%(n+1)]==0 && pos[0]) {
            pit[++pit[0].time].id = i%(n+1);
            pit[pit[0].time].time = i-pos[pos[0]];
            pit[pit[0].time].from = pos[pos[0]]%(n+1);
            b[pos[pos[0]--]%(n+1)]--;
            b[i%(n+1)]++;
        }
    }

    sort(pit+1, pit+pit[0].time+1, Pit::cmp);
}

int main() {
    freopen("way.in", "r", stdin);
    freopen("way.out", "w", stdout);

    static int a[maxn+1];
    int t, n, q;
    scanf("%d", &t);
    for (; t; t--) {
        scanf("%d %d", &n, &q);
        for (int i=0; i<n; i++) {
            scanf("%d", a+i);
            a[i] -= n-1;
        }
        a[n] = 1;

        static Pit pit[maxn+1];
        static Ques que[maxq+1];
        static int ans[maxq+1];
        initPit(n, a, pit);
        for (int i=1; i<=q; i++) {
            scanf("%lld", &que[i].x);
            que[i].id = i;
        }
        sort(que+1, que+q+1, Ques::cmp);

        for (int i=1, j=1; i<=q; i++) {
            ll x=que[i].x;
            for (; j<=pit[0].time && pit[j].time<=x/n; j++) {
                a[pit[j].id] = 1;
                a[pit[j].from] = 1;
            }

            ans[que[i].id] = (a[x%n]>0)+(a[x%(n+1)]==2);
        }

        for (int i=1; i<=q; i++) printf("%d ", n-1+ans[i]);
        printf("\n");
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
